home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / misc / cookies.lha / Cookie / cookhash_old.c < prev    next >
C/C++ Source or Header  |  1995-04-20  |  1KB  |  74 lines

  1. /* cookhash - read a sayings file and generate an index file
  2.  * by Karl Lehenbauer (karl@sugar.uu.net, uunet!sugar!karl)
  3.  *  cookhash.c  1.1  1/12/89
  4.  */
  5.  
  6. /*
  7.  * 1995-04-19 [JöG] Allowed comments after the "%%"
  8.  *                  didn't bump revision though
  9.  *
  10.  *
  11.  *
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16.  
  17. #define YES 1
  18. #define NO 0
  19. #define METACHAR '%'
  20.  
  21. main(int argc,char *argv[])
  22. {
  23.     int c, sawmeta=0;
  24.     long charpos = 0;
  25.  
  26.     if (argc != 1)
  27.     {
  28.         fprintf(stderr,"usage: cookhash <cookiefile >hashfile\n");
  29.         exit(1);
  30.     }
  31.  
  32.     /* write out the "address" of the first cookie */
  33.     puts("000000");
  34.  
  35.     /* read the cookie until the end,
  36.      *   whenever the end-of-cookie ("%%") sequence is found,
  37.      *   the "address" (file position) of the first byte following
  38.      *   it (start of next cookie) is written to the index (hash) file
  39.      */
  40.     while ((c = getchar()) != EOF)
  41.     {
  42.         if (c == METACHAR)
  43.         {
  44.             if (sawmeta)
  45.             {
  46.                 /* Now, allow for comment after the "%%" */
  47.  
  48.                 while((c=getchar())!='\n')
  49.                 {
  50.                     if(c==EOF)
  51.                     {    exit(2);
  52.                     }
  53.  
  54.                     charpos++;
  55.                 }
  56.  
  57.                 charpos++;    /* Compensate for uncounted '\n' */
  58.  
  59.                 printf("%06lx\n",charpos+1);
  60.                 sawmeta = NO;
  61.             }
  62.             else
  63.                 sawmeta = YES;
  64.         }
  65.         else
  66.             sawmeta = NO;
  67.         charpos++;
  68.     }
  69.  
  70.     exit(0);
  71. }
  72.  
  73. /* end of cookhash.c */
  74.